import axios from 'axios'
import {message} from 'antd'
// axios.defaults.baseURL = 'http://localhost:3000'

axios.interceptors.request.use(
    config => {
        config.headers = {
            'Content-Type': 'application/json',
        }
        return config
    }
)
export async  function  getReq(path,data={}){
    try {
        const result = await axios.get(path,{ params: data })
        if (result.status==200) {
            if(result.data.status != 0){
                message.error(result.data.msg)
                return {msg:result.data.msg}
            }

            if (typeof result.data.data === 'string') {

                message.success(result.data.data)
            }
            return {...result.data}
        }else{
            message.error('网络异常')
            return {msg:'网络异常'}
        }
    } catch (err) {
        message.error('系统异常')
        return {msg:'系统异常'}
    }
}
export async  function  postReqLog(path,data){
    try {
        path = `${path}?username=${data.username}&password=${data.password}`
        const result = await axios.post('api/login',data)
        if (result.status==200) {
            if(result.data.status===1){
                message.error(result.data.msg)
                return {msg:result.data.msg}
            }
            return {...result.data}
        }else{
            message.error('网络异常')
            return {msg:'网络异常'}
        }
    } catch (err) {
        message.error('系统异常')
        return {msg:'系统异常'}
    }
}